#include "AddProductWindow.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include "Product.h"
#include <QMessageBox>



AddProductWindow::AddProductWindow(QWidget *parent) :
        QMainWindow(parent),
        addButton(tr("Add product"), this)

{

inputProduct1.setVisible(true);

    this->setCentralWidget(&centralWidget);

    QVBoxLayout *mainLayout = new QVBoxLayout(&centralWidget);
    QLabel *inputProductLabel = new QLabel(tr("Product:"), this);

    QLabel *outputFatLabel = new QLabel(tr("Fat:"), this);
    QLabel *outputCarLabel = new QLabel(tr("Carbohydrate:"), this);
    QLabel *outputProteinLabel = new QLabel(tr("Protein:"), this);
    QLabel *outputEnergyLabel = new QLabel(tr("Energy:"), this);
    QHBoxLayout *layout = new QHBoxLayout();
    mainLayout->addWidget(inputProductLabel);
    mainLayout->addWidget(&inputProduct1);
   // mainLayout->addWidget(&addButton);
    mainLayout->addWidget(outputFatLabel);
    mainLayout->addWidget(&inputFat1);
    mainLayout->addWidget(outputCarLabel);
    mainLayout->addWidget(&inputCarbohydrate1);
    mainLayout->addWidget(outputProteinLabel);
    mainLayout->addWidget(&inputProtein1);
    mainLayout->addWidget(outputEnergyLabel);
    mainLayout->addWidget(&inputEnergy1);
    mainLayout->addWidget(&addButton);


   connect(&addButton, SIGNAL(clicked()),
            this, SLOT(onAddButtonClicked()));

}

void AddProductWindow::onAddButtonClicked()
{
    Product *product=new Product;
    product->setName(inputProduct1.text());
    product->setProtein(inputProtein1.text().toDouble());
    product->setFat(inputFat1.text().toDouble());
    product->setCarbohydrate(inputCarbohydrate1.text().toDouble());
    product->setEnergy(inputEnergy1.text().toDouble());

    if (product->inBase())
    {
        QMessageBox::information(this, tr("Bridget"), tr("This product is already in the base."));
    }
    else
    {
    product->addProduct();

    QMessageBox::information(this, tr("Bridget"), tr("Product is added in base."));

}
}
